<?php

namespace app\admin\model;

use think\Model;

class Site extends Model
{
    // 表名
    protected $name = 'site';
    
    // 自动写入时间戳字段
    protected $autoWriteTimestamp = false;

    // 定义时间戳字段名
    protected $createTime = false;
    protected $updateTime = false;
    
    // 追加属性
    protected $append = [
//        'organization_id_text',
        'building_customer_type_text',
        'building_begin_time_text',
        'building_end_time_text',
        'building_status_text',
//        'building_sheet_text',
        'building_create_time_text',
        'building_is_encore_text',
        'last_update_time_text'
    ];
    

    
//    public function getOrganizationIdList()
//    {
//        return ['5' => __('Organization_id 5')];
//    }

    public function getBuildingCustomerTypeList()
    {
        return ['1' => __('Building_customer_type 1'), '2' => __('Building_customer_type 2')];
    }     

    public function getBuildingStatusList()
    {
        return ['1' => __('Building_status 1'), '2' => __('Building_status 2'), '3' => __('Building_status 3')];
    }

//    public function getBuildingSheetList()
//    {
//        return ['2' => __('Building_sheet 2')];
//    }

    public function getBuildingIsEncoreList()
    {
        return ['0' => __('Building_is_encore 0'), '1' => __('Building_is_encore 1')];
    }


//    public function getOrganizationIdTextAttr($value, $data)
//    {
//        $value = $value ? $value : $data['organization_id'];
//        $list = $this->getOrganizationIdList();
//        return isset($list[$value]) ? $list[$value] : '';
//    }


    public function getBuildingCustomerTypeTextAttr($value, $data)
    {        
        $value = $value ? $value : $data['building_customer_type'];
        $list = $this->getBuildingCustomerTypeList();
        return isset($list[$value]) ? $list[$value] : '';
    }


    public function getBuildingBeginTimeTextAttr($value, $data)
    {
        $value = $value ? $value : $data['building_begin_time'];
        return is_numeric($value) ? date("Y-m-d H:i:s", $value) : $value;
    }


    public function getBuildingEndTimeTextAttr($value, $data)
    {
        $value = $value ? $value : $data['building_end_time'];
        return is_numeric($value) ? date("Y-m-d H:i:s", $value) : $value;
    }


    public function getBuildingStatusTextAttr($value, $data)
    {
        $value = $value ? $value : $data['building_status'];
        $list = $this->getBuildingStatusList();
        return isset($list[$value]) ? $list[$value] : '';
    }


//    public function getBuildingSheetTextAttr($value, $data)
//    {
//        $value = $value ? $value : $data['building_sheet'];
//        $list = $this->getBuildingSheetList();
//        return isset($list[$value]) ? $list[$value] : '';
//    }


    public function getBuildingCreateTimeTextAttr($value, $data)
    {
        $value = $value ? $value : $data['building_create_time'];
        return is_numeric($value) ? date("Y-m-d H:i:s", $value) : $value;
    }


    public function getBuildingIsEncoreTextAttr($value, $data)
    {        
        $value = $value ? $value : $data['building_is_encore'];
        $list = $this->getBuildingIsEncoreList();
        return isset($list[$value]) ? $list[$value] : '';
    }


    public function getLastUpdateTimeTextAttr($value, $data)
    {
        $value = $value ? $value : $data['last_update_time'];
        return is_numeric($value) ? date("Y-m-d H:i:s", $value) : $value;
    }

    protected function setBuildingBeginTimeAttr($value)
    {
        return $value && !is_numeric($value) ? strtotime($value) : $value;
    }

    protected function setBuildingEndTimeAttr($value)
    {
        return $value && !is_numeric($value) ? strtotime($value) : $value;
    }

    protected function setBuildingCreateTimeAttr($value)
    {
        return $value && !is_numeric($value) ? strtotime($value) : $value;
    }

    protected function setLastUpdateTimeAttr($value)
    {
        return $value && !is_numeric($value) ? strtotime($value) : $value;
    }


}
